package top.as.sean.common.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import top.as.sean.common.response.RespStatus;

/**
 * 自定义异常处理
 *
 * @author: ArchieSean
 * @create: 2021-10-22 14:12
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class GlobalException extends RuntimeException {
    /**
     * 异常编码
     */
    private String code;
    /**
     * 异常信息
     */
    private String msg;

    public GlobalException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public GlobalException(String msg) {
        super(msg);
        this.code = RespStatus.FAIL.getCode();
        this.msg = msg;
    }

    /**
     * 异常
     *
     * @param exception 异常
     */
    public GlobalException(RespStatus exception) {
        super(exception.getMsg());
        this.code = exception.getCode();
        this.msg = exception.getMsg();
    }

}